<template>
    <a-collapse v-model="panelActiveKeys" accordion>
        <a-collapse-panel key="main">
            <div slot="header">
                <a-tag color="#87d068">{{i18n('mainTable','主表')}}</a-tag>
                <span>{{formConfig.main.name}}<span>({{formConfig.main.tableName}})</span></span>
            </div>
            <form-codegen-business-edit3-panel ref="main" :config="formConfig.main" :formData="formData" />
        </a-collapse-panel>
        <a-collapse-panel v-for="sub in formConfig.sub" :key="sub.tableName" forceRender>
            <div slot="header">
                <a-tag color="#87d068">{{i18n('subTable','子表')}}</a-tag>
                <span>{{sub.name}}<span>({{sub.tableName}})</span></span>
            </div>
            <form-codegen-business-edit3-panel :ref="sub.tableName" :config="sub" :formData="formData" />
        </a-collapse-panel>
    </a-collapse>
</template>

<script>
    import FormCodegenBusinessEdit3 from "./FormCodegenBusinessEdit3.js";

    export default {
        name: "FormCodegenBusinessEdit3",
        mixins:[FormCodegenBusinessEdit3],
        methods:{
            i18n(name,text,key){
                return this.$ti18(name,text,"formCodegenBusiness.edit3",key);
            },
            handleSubmit(self, this_,callback) {
                var result = this_.$refs.main.getData();
                if (!result.success) {
                    this_.$message.warning(this.i18n('mainTable','主表')+"(" + this_.formConfig.main.name + ")：" + result.message);
                    return callback(true);
                }
                this_.formConfig.main = result.data;
                if (!this_.formConfig.main.className) {
                    this_.$message.warning(this.i18n('mainTable','主表')+"(" + this_.formConfig.main.name + ")："+this.i18n('classNameRequire','类名必填!'));
                    return callback(true);
                }
                if (!this_.formConfig.main.package) {
                    this_.$message.warning(this.i18n('mainTable','主表')+"(" + this_.formConfig.main.name + ")："+this.i18n('packageRequire','包名必填!'));
                    return callback(true);
                }if (!this_.formConfig.main.packageName) {
                    this_.$message.warning(this.i18n('mainTable','主表')+"(" + this_.formConfig.main.name + ")："+this.i18n('packageNameRequire','子系统名称必填!'));
                    return callback(true);
                }
                for (var i = 0; i < this_.formConfig.sub.length; i++) {
                    var sub = this_.formConfig.sub[i];
                    result = this_.$refs[sub.tableName][0].getData();
                    if (!result.success) {
                        this_.$message.warning(this.i18n('subTable','子表')+"(" + sub.name + ")：" + result.message);
                        return callback(true);
                    }
                    Object.assign(sub, result.data);
                    if (!sub.className) {
                        this_.$message.warning(this.i18n('subTable','子表')+"(" + sub.name + ")："+this.i18n('classNameRequire','类名必填!'));
                        return callback(true);
                    }
                    if (!sub.package) {
                        this_.$message.warning(this.i18n('subTable','子表')+"(" + sub.name + ")："+this.i18n('packageRequire','包名必填!'));
                        return callback(true);
                    }
                    if (!sub.packageName) {
                        this_.$message.warning(this.i18n('subTable','子表')+"(" + sub.name + ")："+this.i18n('packageNameRequire','子系统名称必填!'));
                        return callback(true);
                    }
                }
                this_.settingJson.formConfig = this_.formConfig;
                this_.formData.settingJson = JSON.stringify(this_.settingJson);
                this_.$emit("changeForm", this_.formData);
                callback();
            }
        }
    }
</script>

<style scoped>

</style>